package com.designMode.interpreter.terminal;

import com.designMode.interpreter.AbstractExpression;
import com.designMode.interpreter.Context;
import com.designMode.interpreter.TerminalExpression;

/**
 * 布尔型终结符
 */
public class MyBoolean extends TerminalExpression {
    public static final MyBoolean TRUE = new MyBoolean(true);
    public static final MyBoolean FALSE = new MyBoolean(false);
    private final boolean value;

    public MyBoolean(boolean value) {
        this.value = value;
    }

    @Override
    public Object interpret(Context ctx) {
        return value;
    }

    @Override
    public boolean equals(AbstractExpression obj) {
        if (obj != null && obj instanceof MyBoolean) {
            return this.value == ((MyBoolean) obj).value;
        }
        return false;
    }


    @Override
    public String toString() {
        return String.valueOf(value);
    }
}
